import axios from "axios"

export default {
    // 获取商品数据
    get: ({ curPage, eachPage }) =>
        axios.get('/api/commodity', {
            params: {
                curPage,
                eachPage,
            }
        }).then(({ data }) => data),

    // 新增商品数据
    add: ({ name, guarantee, storeCondition, aftersale, place, specs, pack, sales, desc }) =>
        axios({
            method: 'post',
            url: '/api/commodity/add',
            data: { name, guarantee, storeCondition, aftersale, place, specs, pack, sales, desc },
        }).then(({ data }) => data),

    // 删除商品数据  
    del: _id =>
        axios({
            method: 'delete',
            url: '/api/commodity/remove',
            data: { _id }
        }).then(data => data),

    // 通过商品名称查找商品数据
    find: (name) =>
        axios.get('/api/commodity/find', {
            params: {
                name
            }
        }).then(({ data }) => data),

    // 修改商品数据
    edit: (data) =>
        axios({
            method: 'put',
            url: "/api/commodity/edit",
            data: data,
        }).then((data) => data),

    //  删除图片
    delImgs: (_id, url) =>
        axios({
            method: 'delete',
            url: `/res/commodity/del`,
            data: { _id, url }
        }).then(({ data }) => data),

    // 上传图片
    uploadImg: ({ name, _id }) =>
        axios({
            method: 'post',
            url: '/resource/commodity/upload',
            data: { name, _id },
        }).then(({ data }) => data),
    // 修改商品类型
    resComType: (info) => axios.patch("/api/commodity/resComType", info).then(({ data }) => data),

    //  删除详情图片
    delDetailsImgs: (_id, url) =>
        axios({
            method: 'delete',
            url: `/res/commodity/delDetails`,
            data: { _id, url }
        }).then(({ data }) => data),

}



